package top.itmeans.yes.portal.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.itmeans.yes.common.api.CommonResult;
import top.itmeans.yes.entity.Product;
import top.itmeans.yes.entity.ProductCategory;
import top.itmeans.yes.entity.Subject;
import top.itmeans.yes.portal.domain.HomeContentResult;
import top.itmeans.yes.portal.service.HomeService;

import java.util.List;

/**
 * 首页内容管理Controller
 * @author Yiming.Cao
 */
@RequestMapping("/home")
@RestController
@Api(tags = "HomeController")
public class HomeController {
    @Autowired
    private HomeService homeService;

    @ApiOperation("首页内容信息展示")
    @GetMapping("/content")
    public CommonResult<HomeContentResult> content() {
        HomeContentResult contentResult = homeService.content();
        return CommonResult.success(contentResult);
    }

    @ApiOperation("分页获取推荐商品")
    @GetMapping("/recommendProduct")
    public CommonResult<Page<Product>> recommendProductList(@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page<Product> productPage = homeService.recommendProductList(pageSize, pageNum);
        return CommonResult.success(productPage);
    }

    @ApiOperation("获取首页商品分类")
    @GetMapping("/productCate/{parentId}")
    public CommonResult<List<ProductCategory>> getProductCateList(@PathVariable Long parentId) {
        List<ProductCategory> productCategoryList = homeService.getProductCateList(parentId);
        return CommonResult.success(productCategoryList);
    }

    @ApiOperation("根据分类获取专题")
    @GetMapping("/subject")
    public CommonResult<Page<Subject>> getSubjectList(@RequestParam(required = false) Long cateId,
                                                      @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        Page<Subject> subjectPage = homeService.getSubjectList(cateId,pageSize,pageNum);
        return CommonResult.success(subjectPage);
    }

    @ApiOperation("分页获取人气推荐商品")
    @GetMapping("/hotProduct")
    public CommonResult<List<Product>> hotProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<Product> productList = homeService.hotProductList(pageNum,pageSize);
        return CommonResult.success(productList);
    }

    @ApiOperation("分页获取新品推荐商品")
    @GetMapping("/newProduct")
    public CommonResult<List<Product>> newProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<Product> productList = homeService.newProductList(pageNum,pageSize);
        return CommonResult.success(productList);
    }
}
